package com.zzzzzz.taglib.ui;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.zzzzzz.common.util.Validator;
import com.zzzzzz.core.dao.search.SearchContainer;
import com.zzzzzz.core.servlet.IncludeUtil;

public class SearchPaginatorTag extends TagSupport {

	@Override
	public int doEndTag() throws JspException {
		try{
			String page = getPage();
			
			if (Validator.isNotNull(page)) {
				IncludeUtil.include(pageContext, page);
			}
			
			return EVAL_PAGE;
			
		}catch (Exception e) {
			throw new JspException(e);
		}
	}

	@Override
	public int doStartTag() throws JspException {
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		request.setAttribute("zzzzzz-ui:search:searchContainer", _searchContainer);
		return SKIP_BODY;
	}
	
	protected String getPage() {
		return _PAGE;
	}

	public void setSearchContainer(SearchContainer<?> searchContainer) {
		_searchContainer = searchContainer;
	}

	private static final String _PAGE = "/taglib/ui/search_paginator/page.jsp";

	private SearchContainer<?> _searchContainer;

}
